package com.chunyu.app.utils;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.SimpleTimeZone;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author cqnieenp
 */

public class DateUtils {
	protected final static Logger logger = LoggerFactory.getLogger(DateUtils.class);
	public final static String DATE_SEPARATOR_DASH = "-";
	public final static String DATE_SEPARATOR_SLASH = "/";
	public final static String DATE_SEPARATOR_TIME = ":";

	public final static String DATE_TIME_HHmmss = "HH:mm:ss";
	public final static String DATE_TIME_HHmmssSSS = "HH:mm:ss.SSS";
	public static SimpleDateFormat FMT_DATE_TIME_HHmmss = new SimpleDateFormat(DATE_TIME_HHmmss);
	public static SimpleDateFormat FMT_DATE_TIME_HHmmssSSS = new SimpleDateFormat(DATE_TIME_HHmmssSSS);

	public static final String DATE_DASH_yyyyMMdd = "yyyy-MM-dd";
	public static final String DATE_DASH_yyyyMM = "yyyy-MM";
	public final static String DATE_DASH_MMyy = "MM-yy";
	public final static String DATE_DASH_yyyyMMddHHmm = "yyyy-MM-dd HH:mm";
	public final static String DATE_DASH_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
	public static final String DATE_DASH_yyyyMMddHHmmssSSS = "yyyy-MM-dd HH:mm:ss.SSS";

	public static SimpleDateFormat FMT_DATE_DASH_yyyyMMdd = new SimpleDateFormat(DATE_DASH_yyyyMMdd);
	public static SimpleDateFormat FMT_DATE_DASH_yyyyMM = new SimpleDateFormat(DATE_DASH_yyyyMM);
	public static SimpleDateFormat FMT_DATE_DASH_MMyy = new SimpleDateFormat(DATE_DASH_MMyy);
	public static SimpleDateFormat FMT_DATE_DASH_yyyyMMddHHmm = new SimpleDateFormat(DATE_DASH_yyyyMMddHHmm);
	public static SimpleDateFormat FMT_DATE_DASH_yyyyMMddHHmmss = new SimpleDateFormat(DATE_DASH_yyyyMMddHHmmss);
	public static SimpleDateFormat FMT_DATE_DASH_yyyyMMddHHmmssSSS = new SimpleDateFormat(DATE_DASH_yyyyMMddHHmmssSSS);

	public static final String DATE_CHN_yyyyMM = "yyyy年MM月";
	public static final String DATE_CHN_yyyyMMdd = "yyyy年MM月dd日";
	public static final String DATE_CHN_yyyyMMddHHmm = "yyyy年MM月dd日  HH时mm分";
	public static final String DATE_CHN_yyyyMMddHHmmss = "yyyy年MM月dd日  HH时mm分ss秒";
	public static final String DATE_CHN_yyyyMMddHHmmssSSS = "yyyy年MM月dd日  HH时mm分ss秒SSS";
	public static SimpleDateFormat FMT_DATE_CHN_yyyyMM = new SimpleDateFormat(DATE_CHN_yyyyMM);
	public static SimpleDateFormat FMT_DATE_CHN_yyyyMMdd = new SimpleDateFormat(DATE_CHN_yyyyMMdd);
	public static SimpleDateFormat FMT_DATE_CHN_yyyyMMddHHmm = new SimpleDateFormat(DATE_CHN_yyyyMMddHHmm);
	public static SimpleDateFormat FMT_DATE_CHN_yyyyMMddHHmmss = new SimpleDateFormat(DATE_CHN_yyyyMMddHHmmss);
	public static SimpleDateFormat FMT_DATE_CHN_yyyyMMddHHmmssSSS = new SimpleDateFormat(DATE_CHN_yyyyMMddHHmmssSSS);

	public final static String DATE_SLASH_yyyyMM = "yyyy/MM";
	public static final String DATE_SLASHE_MMddyy = "MM/dd/yy";
	public final static String DATE_SLASH_MMyy = "MM/yy";
	public final static String DATE_SLASH_yyyyMMdd = "yyyy/MM/dd";
	public final static String DATE_SLASH_yyyyMMddHHmm = "yyyy/MM/dd HH:mm";
	public final static String DATE_SLASH_yyyyMMddHHmmss = "yyyy/MM/dd HH:mm:ss";
	public final static String DATE_SLASH_yyyyMMddHHmmssSSS = "yyyy/MM/dd HH:mm:ss:SSS";

	public static SimpleDateFormat FMT_DATE_SLASH_yyyyMM = new SimpleDateFormat(DATE_SLASH_yyyyMM);
	public static SimpleDateFormat FMT_DATE_SLASHE_MMddyy = new SimpleDateFormat(DATE_SLASHE_MMddyy);
	public static SimpleDateFormat FMT_DATE_SLASH_MMyy = new SimpleDateFormat(DATE_SLASH_MMyy);
	public static SimpleDateFormat FMT_DATE_SLASH_yyyyMMdd = new SimpleDateFormat(DATE_SLASH_yyyyMMdd);
	public static SimpleDateFormat FMT_DATE_SLASH_yyyyMMddHHmm = new SimpleDateFormat(DATE_SLASH_yyyyMMddHHmm);
	public static SimpleDateFormat FMT_DATE_SLASH_yyyyMMddHHmmss = new SimpleDateFormat(DATE_SLASH_yyyyMMddHHmmss);
	public static SimpleDateFormat FMT_DATE_SLASH_yyyyMMddHHmmssSSS = new SimpleDateFormat(DATE_SLASH_yyyyMMddHHmmssSSS);

	public static final String DATE_yyyy = "yyyy";
	public static final String DATE_yyyyMM = "yyyyMM";
	public final static String DATE_yyyyMMdd = "yyyyMMdd";
	public final static String DATE_yyyyMMddHHmm = "yyyyMMddHHmm";
	public final static String DATE_yyyyMMddHHmmss = "yyyyMMddHHmmss";
	public final static String DATE_yyyyMMddHHmmssSSS = "yyyyMMddHHmmssSSS";
	public static SimpleDateFormat FMT_DATE_yyyy = new SimpleDateFormat(DATE_yyyy);
	public static SimpleDateFormat FMT_DATE_yyyyMM = new SimpleDateFormat(DATE_yyyyMM);
	public static SimpleDateFormat FMT_DATE_yyyyMMdd = new SimpleDateFormat(DATE_yyyyMMdd);
	public static SimpleDateFormat FMT_DATE_yyyyMMddHHmm = new SimpleDateFormat(DATE_yyyyMMddHHmm);
	public static SimpleDateFormat FMT_DATE_yyyyMMddHHmmss = new SimpleDateFormat(DATE_yyyyMMddHHmmss);
	public static SimpleDateFormat FMT_DATE_yyyyMMddHHmmssSSS = new SimpleDateFormat(DATE_yyyyMMddHHmmssSSS);

	/**
	 * 将格式为yyyy-MM-dd的时间串（dataString）转换为Date类型
	 * 
	 * @param dataStr
	 * @return
	 */
	public static Date str2Date(String dataStr) {
		synchronized (dataStr) {
			if (NullUtils.isEmpty(dataStr)) {
				return null;
			} else if (StringUtils.isNumber(dataStr)) {
				return new Date(Long.valueOf(dataStr));
			}
			int dateLen = dataStr.length();
			if (dateLen < 6 || dateLen > 23) {
				return null;
			}
			try {
				if (dateLen == 6) {
					return FMT_DATE_yyyyMM.parse(dataStr);
				} else if (dateLen == 7 && dataStr.indexOf(DATE_SEPARATOR_DASH) > 0) {
					return FMT_DATE_DASH_yyyyMM.parse(dataStr);
				} else if (dateLen == 7 && dataStr.indexOf(DATE_SEPARATOR_SLASH) > 0) {
					return FMT_DATE_SLASH_yyyyMM.parse(dataStr);
				} else if (dateLen == 7 && dataStr.indexOf("年") > 0) {
					return FMT_DATE_CHN_yyyyMM.parse(dataStr);
				} else if (dateLen == 8) {
					return FMT_DATE_yyyyMMdd.parse(dataStr);
				} else if (dateLen == 10 && dataStr.indexOf(DATE_SEPARATOR_DASH) > 0) {
					return FMT_DATE_DASH_yyyyMMdd.parse(dataStr);
				} else if (dateLen == 10 && dataStr.indexOf(DATE_SEPARATOR_SLASH) > 0) {
					return FMT_DATE_SLASH_yyyyMMdd.parse(dataStr);
				} else if (dateLen == 10 && dataStr.indexOf("年") > 0) {
					return FMT_DATE_CHN_yyyyMMdd.parse(dataStr);
				} else {
					return str2DateTime(dataStr);
				}
			} catch (Exception e) {
				logger.error("parseDate:" + dataStr, e);
			}
			return null;
		}
	}

	/**
	 * 将格式为 yyyy-MM-dd HH:mm:ss的时间串转换为Date类型<Br>
	 * 支持格式为yyyy/MM/dd HH:mm:ss
	 * 
	 * @param dateTimeStr
	 * @return
	 */
	public static Date str2DateTime(String dateTimeStr) {
		if (NullUtils.isEmpty(dateTimeStr)) {
			return null;
		}
		int dateLen = dateTimeStr.length();
		if (dateLen < 8 || dateLen > 23 || !(dateLen == 12 || dateLen == 14 || dateLen == 17 || dateLen == 19 || dateLen == 23)) {
			return null;
		}
		try {
			if (dateLen == 12) {
				return FMT_DATE_yyyyMMddHHmm.parse(dateTimeStr);
			} else if (dateLen == 17 && dateTimeStr.indexOf(DATE_SEPARATOR_DASH) > 0) {
				return FMT_DATE_DASH_yyyyMMddHHmm.parse(dateTimeStr);
			} else if (dateLen == 17 && dateTimeStr.indexOf(DATE_SEPARATOR_SLASH) > 0) {
				return FMT_DATE_SLASH_yyyyMMddHHmm.parse(dateTimeStr);
			} else if (dateLen == 17 && dateTimeStr.indexOf("年") > 0) {
				return FMT_DATE_CHN_yyyyMMddHHmm.parse(dateTimeStr);
			} else if (dateLen == 14) {
				return FMT_DATE_yyyyMMddHHmmss.parse(dateTimeStr);
			} else if (dateLen == 19 && dateTimeStr.indexOf(DATE_SEPARATOR_DASH) > 0) {
				return FMT_DATE_DASH_yyyyMMddHHmmss.parse(dateTimeStr);
			} else if (dateLen == 19 && dateTimeStr.indexOf(DATE_SEPARATOR_SLASH) > 0) {
				return FMT_DATE_SLASH_yyyyMMddHHmmss.parse(dateTimeStr);
			} else if (dateLen == 19 && dateTimeStr.indexOf("年") > 0) {
				return FMT_DATE_CHN_yyyyMMddHHmmss.parse(dateTimeStr);
			} else if (dateLen == 17) {
				return FMT_DATE_yyyyMMddHHmmssSSS.parse(dateTimeStr);
			} else if (dateLen == 23 && dateTimeStr.indexOf(DATE_SEPARATOR_DASH) > 0) {
				return FMT_DATE_DASH_yyyyMMddHHmmssSSS.parse(dateTimeStr);
			} else if (dateLen == 23 && dateTimeStr.indexOf(DATE_SEPARATOR_SLASH) > 0) {
				return FMT_DATE_SLASH_yyyyMMddHHmmssSSS.parse(dateTimeStr);
			} else if (dateLen == 23 && dateTimeStr.indexOf("年") > 0) {
				return FMT_DATE_CHN_yyyyMMddHHmmssSSS.parse(dateTimeStr);
			} else {
				return null;
			}
		} catch (Exception e) {
			logger.error("parseDate:" + dateTimeStr, e);
		}
		return null;
	}

	/**
	 * 指定格式转化时间字符串
	 * 
	 * @param dataString
	 * @param format
	 * @return
	 */
	public static Date str2Date(String dataString, String format) {
		if (NullUtils.isEmpty(dataString)) {
			return null;
		}
		DateFormat dateFormat = new SimpleDateFormat(format);
		try {
			return dateFormat.parse(dataString);
		} catch (ParseException e) {
			return str2Date(dataString);
		}
	}

	/**
	 * 转化为本地时间
	 * 
	 * @param dateString
	 * @param format
	 * @return
	 */

	public static Date str2LocaleDate(String dateString, String format) {
		DateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH);
		return formatter.parse(dateString, new ParsePosition(0));
	}

	/** 字符转换日历(动态格式转换) */
	public static Calendar str2Calendar(String dateStr) {
		if (NullUtils.isEmpty(dateStr)) {
			return null;
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(str2Date(dateStr));
		return cal;
	}

	/** 字符转换日历(动态格式转换) */
	public static Calendar str2Calendar(String dateStr, String type) {
		if (NullUtils.isEmpty(dateStr)) {
			return null;
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(str2Date(dateStr, type));
		return cal;
	}

	/** 日期转日历* */
	public static Calendar date2Calendar(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal;
	}

	/**
	 * 两时间相减 返回格式:天数-小时-分钟
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static String minusTwoTimeddHHmm(String endTime, String startTime) {
		try {
			Date d1 = str2Date(startTime);
			Date d2 = str2Date(endTime);
			long diff = d1.getTime() - d2.getTime();// 这样得到的差值是微秒级别
			long days = diff / (1000 * 60 * 60 * 24);
			long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
			long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
			if (hours < 0) {
				hours = new BigDecimal(hours).abs().intValue();
			}
			if (minutes < 0) {
				minutes = new BigDecimal(minutes).abs().intValue();
			}
			return "" + days + "-" + hours + "-" + minutes;
		} catch (Exception e) {
			logger.error("getMinusTwoTimeddHHmm:", e);
		}
		return "";
	}

	/**
	 * 两时间相减 返回时间相差天数
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static String minusTwoTimedd(String endTime, String startTime) {
		try {
			Date d1 = str2Date(startTime);
			Date d2 = str2Date(endTime);
			long diff = d1.getTime() - d2.getTime();// 这样得到的差值是微秒级别
			long days = diff / (1000 * 60 * 60 * 24);
			return String.valueOf(days);
		} catch (Exception e) {
			logger.error("getMinusTwoTimedd:", e);
		}
		return "";
	}

	/**
	 * 
	 * @param dateTime
	 * 
	 * @return unix 时间 yyyy-MM-dd HH:mm:ss
	 */
	public static String toUnixTimeStamp(String dateTime) {
		Calendar c = Calendar.getInstance();
		c.setTime(str2Date(dateTime));
		return (c.getTimeInMillis() / 1000) + "";
	}

	/**
	 * unix 时间 转换
	 * 
	 * @param timestampString
	 *            1252639886
	 * @param formats
	 * @return
	 */
	public static String toUnixTime2String(String timestampString, String formats) {
		if (StringUtils.isBlank(timestampString) || "null".equals(timestampString)) {
			return "";
		}
		Long timestamp = Long.parseLong(timestampString) * 1000;
		String date = new java.text.SimpleDateFormat(formats).format(new java.util.Date(timestamp));
		return date;
	}

	/**
	 * 获取当前时间
	 * 
	 * @return
	 */
	public static Date currentDate() {
		return str2Date(date2Str(currentDateTime()));
	}

	/**
	 * 获取当前时间
	 * 
	 * @return
	 */
	public static Date currentDateTime() {
		return new Date();
	}

	/**
	 * 获取当前时间日历
	 * 
	 * @return
	 */
	public static Calendar currentCalendar() {
		return calendar(currentDateTime());
	}

	/**
	 * 获取当前时间日历
	 * 
	 * @return
	 */
	public static Calendar calendar(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar;
	}

	/**
	 * 功能：返回年
	 * 
	 * @param date
	 * @return
	 */
	public static Integer currentYear() {
		return getYear(currentDateTime());

	}

	/**
	 * 功能：返回月
	 * 
	 * @param date
	 * @return
	 */
	public static Integer currentMonth() {
		return getMonth(currentDateTime());
	}

	/**
	 * 功能：返回日
	 * 
	 * @param date
	 * @return
	 */
	public static Integer currentDay() {
		return getDay(currentDateTime());
	}

	/**
	 * 获取当前小时
	 * 
	 * @param date
	 * @return
	 */
	public static Integer currentHour() {
		return getHour(currentDateTime());
	}

	/**
	 * 获取当前分钟
	 * 
	 * @param date
	 * @return
	 */
	public static Integer currentMinute() {
		return getMinute(currentDateTime());
	}

	/**
	 * 获取当前秒
	 * 
	 * @param date
	 * @return
	 */
	public static Integer currentSecond() {
		return getSecond(currentDateTime());
	}

	/**
	 * 获取当前毫秒
	 * 
	 * @param date
	 * @return
	 */
	public static Long currentMillis() {
		return getMillis(currentDateTime());
	}

	/**
	 * 取得当前季度值
	 * 
	 * @return
	 */
	public static int currentQuarter() {
		int month = currentMonth() + 1;
		if (month < 4) {
			return 1;
		} else if (month < 7) {
			return 2;
		} else if (month < 10) {
			return 3;
		} else {
			return 4;
		}
	}

	/**
	 * 获取当前月的第一天
	 * 
	 * @param date
	 * @return
	 */
	public static Date currentMonthFirstDay() {
		return getMonthFirstDay(currentDateTime());
	}

	/**
	 * 获取当前月的最后一天
	 * 
	 * @param date
	 * @return
	 */
	public static Date currentMonthLastDay() {
		return getMonthLastDay(currentDateTime());
	}

	/**
	 * 获取当年的最后一天
	 * 
	 * @param year
	 * @return
	 */
	public static Date currYearLastDay() {
		Calendar currCal = Calendar.getInstance();
		int currentYear = currCal.get(Calendar.YEAR);
		Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(Calendar.YEAR, currentYear);
		calendar.roll(Calendar.DAY_OF_YEAR, -1);
		Date currYearLast = calendar.getTime();
		return currYearLast;
	}

	/**
	 * 功能：传入时间按所需格式返回时间字符串
	 * 
	 * @param date
	 *            java.util.Date格式
	 * @param format
	 *            yyyy-MM-dd HH:mm:ss | yyyy年MM月dd日 HH时mm分ss秒
	 * @return
	 */
	public static String date2Str(Date date, String format) {
		String result = "";
		try {
			if (NullUtils.isEmpty(date)) {
				date = new Date();// 如果时间为空,则默认为当前时间
			}
			if (StringUtils.isBlank(format)) {// 默认格式化形式
				format = DATE_DASH_yyyyMMdd;
			}
			DateFormat df = new SimpleDateFormat(format);
			result = df.format(date);
		} catch (Exception e) {
			logger.error("format", e);
		}
		return result;
	}

	/**
	 * 功能：时间字符串格式转换
	 * 
	 * @param dateStr
	 *            时间字符串
	 * @param fromFormat
	 *            时间字符串的格式
	 * @param toFormat
	 *            格式为的格式
	 * @return
	 */
	public static String date2Str(String dateStr, String fromFormat, String toFormat) {
		return date2Str(str2Date(dateStr, fromFormat), toFormat);
	}

	/**
	 * 功能：格式化rss的时间 输入:
	 * 
	 * @param date
	 * @return
	 */
	public static String date2RssStr(Date date) {
		if (date == null) {
			date = new Date();// 如果时间为空,则默认为当前时间
		}
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
		SimpleTimeZone zone = new SimpleTimeZone(8, "GMT");
		sdf.setTimeZone(zone);
		return sdf.format(date);
	}

	/**
	 * 将日期转换成Julian日期，即为哪一年的第几天
	 * 
	 * @param date
	 * @return
	 */
	public static int date2Julian(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR) % 100;
		int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
		return year * 1000 + dayOfYear;
	}

	public static Date Date2StartTime(Date date) {
		Calendar calendar = date2Calendar(date);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);

		return calendar.getTime();
	}

	public static Date Date2EndTime(Date date) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = date2Calendar(date);
		calendar.set(Calendar.HOUR_OF_DAY, 23);
		calendar.set(Calendar.MINUTE, 59);
		calendar.set(Calendar.SECOND, 59);
		calendar.set(Calendar.MILLISECOND, 999);

		return calendar.getTime();
	}

	/**
	 * 
	 * @param dateTime
	 *            yyyy-MM-dd HH:mm:ss
	 * @return unix 时间
	 */
	public static String date2UnixTimeStampStr(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return (c.getTimeInMillis() / 1000) + "";
	}

	/**
	 * @param string
	 * @return
	 */
	public static String date2Str(Date date) {
		return FMT_DATE_DASH_yyyyMMdd.format(date);
	}

	/**
	 * @param string
	 * @return
	 */
	public static String dateTime2Str(Date date) {
		return FMT_DATE_DASH_yyyyMMddHHmmss.format(date);
	}

	/**
	 * 功能：获取当前日期 格式:yyyy
	 * 
	 * @return String yyyy
	 */
	public static String date2YyyyStr(Date date) {
		return FMT_DATE_yyyy.format(date);
	}

	/**
	 * 功能：获取当前日期 格式:yyyy-MM
	 * 
	 * @return String yyyy-MM
	 */
	public static String date2DashYyyyMMStr(Date date) {
		return FMT_DATE_DASH_yyyyMM.format(date);
	}

	public static String date2DashYyyyMMddStr(Date date) {
		return date2Str(date, DATE_DASH_yyyyMMdd);
	}

	public static String date2DashYyyyMMddHHmmssStr(Date date) {
		return date2Str(date, DATE_DASH_yyyyMMddHHmmss);
	}

	/**
	 * 获取当前时间中文字符串
	 * 
	 * @return yyyy年MM月
	 */
	public static String date2CHNYyyyMMStr(Date date) {
		return FMT_DATE_CHN_yyyyMM.format(date);
	}

	/**
	 * 获取当前时间中文字符串
	 * 
	 * @return yyyy年MM月dd日
	 */
	public static String date2CHNYyyyMMddStr(Date date) {
		return FMT_DATE_CHN_yyyyMMdd.format(date);
	}

	/**
	 * 获取当前时间中文字符串
	 * 
	 * @return yyyy年MM月dd日 HH时mm分ss秒
	 */
	public static String date2CHNYyyyMMddHHmmssStr(Date date) {
		return FMT_DATE_CHN_yyyyMMddHHmmss.format(date);
	}

	/**
	 * 获得当前年月 public static String CurrrentYyyyMM() {
	 * 
	 * return FMT_DATE_yyyyMM.format(new Date()); }
	 * 
	 * /** 获得"yyyyMMdd"格式的当前日期
	 * 
	 * @return 返回"yyyyMMdd"格式的当前时间
	 */
	public static String date2YyyyMMddStr(Date date) {
		return FMT_DATE_yyyyMMdd.format(date);
	}

	/**
	 * 获得当前年月 public static String CurrrentYyyyMM() {
	 * 
	 * return FMT_DATE_yyyyMM.format(new Date()); }
	 * 
	 * /** 获得"yyyyMMdd"格式的当前日期
	 * 
	 * @return 返回"yyyyMMdd"格式的当前时间
	 */
	public static String date2YyyyMMStr(Date date) {
		return FMT_DATE_yyyyMM.format(date);
	}

	/**
	 * 获得当前年月 public static String CurrrentYyyyMM() {
	 * 
	 * return FMT_DATE_yyyyMM.format(new Date()); }
	 * 
	 * /** 获得"yyyyMMddHHmmss"格式的当前日期
	 * 
	 * @return 返回"yyyyMMddHHmmss"格式的当前时间
	 */
	public static String date2YyyyMMddHHmmssStr(Date date) {
		return FMT_DATE_yyyyMMddHHmmss.format(date);
	}

	/**
	 * 
	 * @param dateTime
	 *            yyyy-MM-dd HH:mm:ss
	 * @return unix 时间
	 */
	public static String currentDate2UnixTimeStampStr() {
		Calendar c = Calendar.getInstance();
		c.setTime(currentDateTime());
		return (c.getTimeInMillis() / 1000) + "";
	}

	/**
	 * @param string
	 * @return
	 */
	public static String currentDate2Str(String pattern) {
		Format formatter = new SimpleDateFormat(pattern);
		return formatter.format(currentDateTime());
	}

	/**
	 * @param string
	 * @return
	 */
	public static String currentDate2Str() {
		return currentDate2DashYyyyMMddStr();
	}

	/**
	 * @param string
	 * @return
	 */
	public static String currentDateTime2Str() {
		return currentDate2DashYyyyMMddHHmmssStr();
	}

	/**
	 * 功能：获取当前日期 格式:yyyy-MM
	 * 
	 * @return String yyyy-MM
	 */
	public static String currentDate2YyyyStr() {
		return FMT_DATE_yyyy.format(currentDateTime());
	}

	/**
	 * 功能：获取当前日期 格式:yyyy-MM
	 * 
	 * @return String yyyy-MM
	 */
	public static String currentDate2DashYyyyMMStr() {
		return FMT_DATE_DASH_yyyyMM.format(currentDateTime());
	}

	/**
	 * 功能：获取当前日期 格式:yyyy-MM-dd
	 * 
	 * @return String yyyy-MM-dd
	 */
	public static String currentDate2DashYyyyMMddStr() {
		return FMT_DATE_DASH_yyyyMMdd.format(currentDateTime());
	}

	/**
	 * 功能：获取当前日期 格式yyyy-MM-dd HH:mm:ss
	 * 
	 * @return String yyyy-MM-dd HH:mm:ss
	 */
	public static String currentDate2DashYyyyMMddHHmmssStr() {
		return FMT_DATE_DASH_yyyyMMddHHmmss.format(currentDateTime());
	}

	/**
	 * 获取当前时间中文字符串
	 * 
	 * @return yyyy年MM月
	 */
	public static String currentDate2CHNYyyyMMStr() {
		return FMT_DATE_CHN_yyyyMM.format(currentDateTime());
	}

	/**
	 * 获取当前时间中文字符串
	 * 
	 * @return yyyy年MM月dd日
	 */
	public static String currentDate2CHNYyyyMMddStr() {
		return FMT_DATE_CHN_yyyyMMdd.format(currentDateTime());
	}

	/**
	 * 获取当前时间中文字符串
	 * 
	 * @return yyyy年MM月dd日 HH时mm分ss秒
	 */
	public static String currentDate2CHNYyyyMMddHHmmssStr() {
		return FMT_DATE_CHN_yyyyMMddHHmmss.format(currentDateTime());
	}

	/**
	 * 获得当前年月 public static String CurrrentYyyyMM() {
	 * 
	 * return FMT_DATE_yyyyMM.format(new Date()); }
	 * 
	 * /** 获得"yyyyMMdd"格式的当前日期
	 * 
	 * @return 返回"yyyyMMdd"格式的当前时间
	 */
	public static String currentDate2YyyyMMddStr() {
		return FMT_DATE_yyyyMMdd.format(currentDateTime());
	}

	/**
	 * 获得当前年月 public static String CurrrentYyyyMM() {
	 * 
	 * return FMT_DATE_yyyyMM.format(new Date()); }
	 * 
	 * /** 获得"yyyyMMdd"格式的当前日期
	 * 
	 * @return 返回"yyyyMMdd"格式的当前时间
	 */
	public static String currentDate2YyyyMMStr() {
		return FMT_DATE_yyyyMM.format(currentDateTime());
	}

	/**
	 * 获得当前年月 public static String CurrrentYyyyMM() {
	 * 
	 * return FMT_DATE_yyyyMM.format(new Date()); }
	 * 
	 * /** 获得"yyyyMMddHHmmss"格式的当前日期
	 * 
	 * @return 返回"yyyyMMddHHmmss"格式的当前时间
	 */
	public static String currentDate2YyyyMMddHHmmssStr() {
		return FMT_DATE_yyyyMMddHHmmss.format(currentDateTime());
	}

	public static String currentDate2YyyyMMddHHmmssSSSStr() {
		return FMT_DATE_yyyyMMddHHmmssSSS.format(currentDateTime());
	}

	/**
	 * HH:mm:ss
	 * 
	 * @return
	 */
	public static String currentTime() {
		return FMT_DATE_TIME_HHmmss.format(currentDateTime());
	}

	/**
	 * HH:mm:ss.SSS
	 * 
	 * @return
	 */
	public static String currentStrTimeStamp() {
		return FMT_DATE_TIME_HHmmssSSS.format(currentDateTime());
	}

	public static synchronized long currentLongTimeStamp() {
		return Long.valueOf(currentDate2YyyyMMddHHmmssSSSStr());
	}

	public static synchronized long currentLongDateTimeStamp() {
		SimpleDateFormat formatter = new SimpleDateFormat(DATE_yyyyMMddHHmmssSSS);
		return Long.valueOf(formatter.format(currentDateTime()));
	}

	/**
	 * 获取当前日期是星期几<br>
	 * 
	 * @return 当前日期是星期几
	 */
	public static String currentWeekDate() {
		String[] weekDays = { "7", "1", "2", "3", "4", "5", "6" };
		// String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
		// "星期六"};

		int w = getChinaWeekDay(currentDateTime());
		if (w < 0) {
			w = 0;
		}
		return weekDays[w];
	}

	/**
	 * 获取当前日期是星期几<br>
	 * 
	 * @return 当前日期是星期几
	 */
	public static String currentWeekCHNDate() {
		String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		int w = getChinaWeekDay(currentDateTime());
		if (w < 0) {
			w = 0;
		}
		return weekDays[w];
	}

	/**
	 * 当前时间加 减days
	 * 
	 * @param DATE_CHN_yyyyMMddHHmmss
	 * @param diffDay
	 * @return
	 */
	public static String currentAddDayCHNStr(int diffDay) {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_MONTH, diffDay);
		return FMT_DATE_CHN_yyyyMMddHHmmss.format(c.getTime());
	}

	/**
	 * 当前时间加 减days
	 * 
	 * @param DATE_DASH_yyyyMMddHHmmss
	 * @param diffDay
	 * @return
	 */
	public static String currentAddDayDashStr(int diffDay) {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_MONTH, diffDay);
		return FMT_DATE_DASH_yyyyMMddHHmmss.format(c.getTime());
	}

	/**
	 * 当前时间加 减days
	 * 
	 * @param DATE_SLASH_yyyyMMddHHmmss
	 * @param diffDay
	 * @return
	 */
	public static String currentAddDaySlashStr(int diffDay) {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_MONTH, diffDay);
		return FMT_DATE_SLASH_yyyyMMddHHmmss.format(c.getTime());
	}

	/**
	 * 
	 * 功能：格式化日期字符串 例如：2008-8 转换为2008-08
	 *
	 * @param dateStr
	 * @return
	 */
	public static String str2DashYyyyMMStr(String dateStr) {
		try {
			Date date = FMT_DATE_DASH_yyyyMM.parse(dateStr);
			return FMT_DATE_DASH_yyyyMM.format(date);
		} catch (ParseException e) {
			logger.error("toDateDashYyyyMMString:", e);
		}
		return null;
	}

	/**
	 * "yyyyMMdd"格式的日期转换为"yyyy-MM-dd"格式的日期
	 * 
	 * @param dateYyyyMMdd
	 *            "yyyyMMdd"格式的日期
	 * @return "yyyy-MM-dd"格式的日期
	 */
	public static String str2DashYyyyMMddStr(String dateYyyyMMdd) {
		try {
			return FMT_DATE_DASH_yyyyMMdd.format(FMT_DATE_yyyyMMdd.parse(dateYyyyMMdd));
		} catch (ParseException e) {
			logger.error("toDateDashYyyyMMddHHmmssString:", e);
		}
		return null;
	}

	/**
	 * "yyyyMMddHHmmss"格式的日期转换为"yyyy-MM-dd HH:mm:ss"格式的日期
	 * 
	 * @param dateYyyyMMddHHmmss
	 *            "yyyyMMddHHmmss"格式的日期
	 * @return "yyyy-MM-dd HH:mm:ss"格式的日期
	 */
	public static String str2DashYyyyMMddHHmmssStr(String dateYyyyMMddHHmmss) {
		try {
			return FMT_DATE_DASH_yyyyMMddHHmmss.format(FMT_DATE_yyyyMMddHHmmss.parse(dateYyyyMMddHHmmss));
		} catch (ParseException e) {
			logger.error("toDateDashYyyyMMddHHmmssString:", e);
		}
		return null;
	}

	/**
	 * 将UNIX时间转换成标准时间
	 * 
	 * @param timestampString
	 * @return
	 */
	public static String str2DashYyyyMMddHHmmssStrFromUnixTime(String timestampString) {
		Long timestamp = Long.parseLong(timestampString) * 1000;
		String date = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(timestamp));
		return date;
	}

	/**
	 * 
	 * 功能：把日期格式转换成yyyyMMDD日期格式
	 *
	 * @param dateStr
	 * @return
	 */
	public static String str2YyyyMMddStr(String dateStr) {
		try {
			return FMT_DATE_DASH_yyyyMMdd.format(str2Date(dateStr));
		} catch (Exception e) {
			logger.error("toDateYyyyMMddString:", e);
		}
		return null;
	}

	/**
	 * 功能：返回年
	 * 
	 * @param date
	 * @return
	 */
	public static Integer getYear(Date date) {
		if (NullUtils.isEmpty(date)) {
			return null;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.YEAR);

	}

	/**
	 * 功能：返回月
	 * 
	 * @param date
	 * @return
	 */
	public static Integer getMonth(Date date) {
		if (NullUtils.isEmpty(date)) {
			return null;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.MONTH) + 1;
	}

	/**
	 * 功能：返回日
	 * 
	 * @param date
	 * @return
	 */
	public static Integer getDay(Date date) {
		if (NullUtils.isEmpty(date)) {
			return null;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 功能：返回月的最大天数
	 * 
	 * @param date
	 * @return
	 */
	public static Integer getMonthMaxDay(Date date) {
		if (NullUtils.isEmpty(date)) {
			return null;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.getActualMaximum(Calendar.DATE);
	}

	/**
	 * 功能：返回月的最大天数
	 * 
	 * @param date
	 * @return
	 */
	public static Integer getMonthMinDay(Date date) {
		if (NullUtils.isEmpty(date)) {
			return null;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.getActualMinimum(Calendar.DATE);
	}

	/**
	 * 功能：返回小时
	 * 
	 * @param date
	 * @return
	 */
	public static int getHour(Date date) {
		if (date == null) {
			date = new Date();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 功能：返回分
	 * 
	 * @param date
	 * @return
	 */
	public static int getMinute(Date date) {
		if (date == null) {
			date = new Date();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.MINUTE);
	}

	/**
	 * 功能：返回星期 1：星期一，2:星期二 ... 6:星期六 7:星期日
	 * 
	 * @param date
	 * @return
	 */
	public static int getChinaWeekDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		int week = c.get(Calendar.DAY_OF_WEEK) - 1;
		if (week == 0) {
			return 7;
		} else {
			return week;
		}
	}

	/**
	 * 获取时间(dt)的DATE_yyyyMMdd格式字符串
	 * 
	 * @param dt
	 * @return
	 */
	public static String getChinaWeekCHNDay(Date dt) {
		String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		Calendar cal = Calendar.getInstance();
		cal.setTime(dt);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	/**
	 * 功能：返回秒
	 * 
	 * @param date
	 * @return
	 */
	public static int getSecond(Date date) {
		if (date == null) {
			date = new Date();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.SECOND);
	}

	/**
	 * 功能：返回毫秒
	 * 
	 * @param date
	 * @return
	 */
	public static long getMillis(Date date) {
		if (date == null) {
			date = new Date();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.getTimeInMillis();
	}

	/**
	 * 功能：获取当某月的第一天日期
	 * 
	 * @return
	 */
	public static Date getMonthFirstDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.set(getYear(date), getMonth(date), getMonthMinDay(date));
		return c.getTime();
	}

	/**
	 * 功能：获取某月的最后一天日期
	 * 
	 * @return
	 */
	public static Date getMonthLastDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.set(getYear(date), getMonth(date), getMonthMaxDay(date));
		c.setTimeInMillis(c.getTimeInMillis() - (24 * 3600 * 1000));
		return c.getTime();
	}

	/**
	 * 获取某月份的最后一天
	 * 
	 * @param YYYY-MM
	 *            月份
	 * @return 输入月份的最后一天
	 * @throws Exception
	 */
	public static String getMonthLastDayStr(String dashYyyyMM) {
		Date date;
		try {
			date = getMonthLastDay(FMT_DATE_DASH_yyyyMM.parse(dashYyyyMM));
			return FMT_DATE_DASH_yyyyMM.format(date);
		} catch (ParseException e) {
			logger.error("toDateYyyyMMddString:", e);
		}
		return null;
	}

	/**
	 * 功能：返回上旬/中旬/下旬 1 ：上旬 2： 中旬 3： 下旬
	 * 
	 * @param date
	 * @return
	 */
	public static int getEarlyMidLate(Date date) {
		int day = getDay(date);
		int earlyMidLate = 0;
		if (1 <= day && day <= 10) {
			earlyMidLate = 1;
		}
		if (11 <= day && day <= 20) {
			earlyMidLate = 2;
		}
		if (20 < day) {
			earlyMidLate = 3;
		}
		return earlyMidLate;
	}

	public static Date getNextMonth(Date time) {
		Calendar calendar = Calendar.getInstance();
		if (null != time) {
			calendar.setTimeInMillis(time.getTime());
		}
		calendar.add(Calendar.MONTH, 1);
		return new Date(calendar.getTimeInMillis());
	}

	public static Date getPreviousMonth(Date time) {
		Calendar calendar = Calendar.getInstance();
		if (null != time) {
			calendar.setTimeInMillis(time.getTime());
		}
		calendar.add(Calendar.MONTH, -1);
		return new Date(calendar.getTimeInMillis());
	}

	public static String getMonthRate(Date date, boolean moveIn) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int day = calendar.get(Calendar.DAY_OF_MONTH);

		int daysOfThisMonth = calendar.getActualMaximum(Calendar.DATE);
		double rate;
		if (moveIn) {
			rate = (double) (daysOfThisMonth - day + 1) / daysOfThisMonth;
		} else {
			rate = (double) day / daysOfThisMonth;
		}
		rate = (double) Math.round(rate * 10) / 10;
		return String.valueOf(rate);
	}

	public static String getMonthRate(Date dateIn, Date DateOut) {
		Calendar calIn = Calendar.getInstance();
		calIn.setTime(dateIn);
		Calendar calOut = Calendar.getInstance();
		calOut.setTime(DateOut);
		int day = calOut.get(Calendar.DAY_OF_MONTH) - calIn.get(Calendar.DAY_OF_MONTH) + 1;
		int daysOfThisMonth = calIn.getActualMaximum(Calendar.DATE);
		double rate = (double) day / daysOfThisMonth;
		rate = (double) Math.round(rate * 10) / 10;
		return String.valueOf(rate);
	}

	/**
	 * 添加年
	 * 
	 * @param date
	 * @param month
	 */
	public static Date addYear(Date date, int year) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.YEAR, year);
		return calendar.getTime();
	}

	/**
	 * 添加月
	 * 
	 * @param date
	 * @param month
	 */
	public static Date addMonth(Date date, int month) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, month);
		return calendar.getTime();
	}

	/**
	 * 获得距离输入月份的diffMonth月的日期
	 * 
	 * @param dateYyyyMM
	 *            "yyyyMM"格式的日期
	 * @param diffMonth
	 *            相差的月数
	 * @return "yyyyMM"格式的日期
	 * @throws ParseException
	 */
	public static String addMonth4YyyyMMStr(String dateYyyyMM, int diffMonth) {
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(FMT_DATE_yyyyMM.parse(dateYyyyMM));
			c.add(Calendar.MONTH, diffMonth);
			return FMT_DATE_yyyyMM.format(c.getTime());
		} catch (ParseException e) {
			logger.error("addMonth4YyyyMM:", e);
		}
		return "";

	}

	/**
	 * 添加天
	 * 
	 * @param date
	 * @param days
	 * @return
	 */
	public static Date addDay(Date date, int days) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, days);
		if (date instanceof java.sql.Date) {
			return new java.sql.Date(calendar.getTime().getTime());
		} else {
			return calendar.getTime();
		}

	}

	/**
	 * 获得距离给定日期diffDay天的日期
	 * 
	 * @param dateYyyyMMdd
	 *            "yyyyMMdd"格式的日期
	 * @param diffDay
	 *            相差的天数
	 * @return "yyyyMMdd"格式的日期
	 * @throws ParseException
	 */
	public static String addDay4YyyyMMddStr(String dateYyyyMMdd, int diffDay) {
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(FMT_DATE_yyyyMMdd.parse(dateYyyyMMdd));
			c.add(Calendar.DATE, diffDay);
			return FMT_DATE_yyyyMMdd.format(c.getTime());
		} catch (ParseException e) {
			logger.error("addDay4YyyyMMddStr:", e);
		}
		return "";
	}

	/**
	 * 添加时
	 * 
	 * @param date
	 * @param hours
	 * @return
	 */
	public static Date addHour(Date date, Double hours) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		if (null == hours) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.HOUR_OF_DAY, hours.intValue());
		if (date instanceof java.sql.Date) {
			return new java.sql.Date(calendar.getTime().getTime());
		} else {
			return calendar.getTime();
		}

	}

	/**
	 * 指定日期加上指定天数
	 * 
	 * @param date
	 * @param minutes
	 * @return
	 */
	public static Date addMinute(Date date, int minutes) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MINUTE, minutes);
		if (date instanceof java.sql.Date) {
			return new java.sql.Date(calendar.getTime().getTime());
		} else {
			return calendar.getTime();
		}

	}

	/**
	 * 指定日期加上指定天数
	 * 
	 * @param date
	 * @param minutes
	 * @return
	 */
	public static Date addSecond(Date date, int second) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.SECOND, second);
		if (date instanceof java.sql.Date) {
			return new java.sql.Date(calendar.getTime().getTime());
		} else {
			return calendar.getTime();
		}

	}

	/**
	 * 添加年，月，天
	 * 
	 * @param date
	 * @param year
	 * @param month
	 * @param day
	 * @return
	 */
	public static Date addYyymmdd(Date date, int year, int month, int day) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.YEAR, year);
		calendar.add(Calendar.MONTH, month);
		calendar.add(Calendar.DATE, day);
		if (date instanceof java.sql.Date) {
			return new java.sql.Date(calendar.getTime().getTime());
		} else {
			return calendar.getTime();
		}
	}

	/**
	 * 添加时，分、秒
	 * 
	 * @param date
	 * @param hour
	 * @param minute
	 * @param second
	 * @return
	 */
	public static Date addHHmmss(Date date, int hour, int minute, int second) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.HOUR, hour);
		calendar.add(Calendar.MINUTE, minute);
		calendar.add(Calendar.SECOND, second);
		if (date instanceof java.sql.Date) {
			return new java.sql.Date(calendar.getTime().getTime());
		} else {
			return calendar.getTime();
		}
	}

	/**
	 * 根据开始日期 ，需要的工作日天数 ，计算工作截止日期，并返回截止日期
	 * 
	 * @param startDate
	 *            开始日期
	 * @param workDay
	 *            工作日天数(周一到周五)
	 * @return Date类型
	 * @createTime 2014-2-14
	 */
	public static Date addWorkDay(Date startDate, int workDay) {
		Calendar c1 = Calendar.getInstance();
		c1.setTime(startDate);
		for (int i = 0; i < workDay; i++) {
			c1.set(Calendar.DATE, c1.get(Calendar.DATE) + 1);
			if (Calendar.SATURDAY == c1.get(Calendar.SATURDAY) || Calendar.SUNDAY == c1.get(Calendar.SUNDAY)) {
				workDay = workDay + 1;
				c1.set(Calendar.DATE, c1.get(Calendar.DATE) + 1);
				continue;
			}
		}
		return c1.getTime();
	}

	/**
	 * 功能：指定日期减去指定天数
	 * 
	 * @param date
	 * @param day
	 * @return
	 */
	public static Date minusDateByDays(Date date, int day) {
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(getMillis(date) - ((long) day) * 24 * 3600 * 1000);
		return c.getTime();
	}

	/**
	 * 功能:两个日期相隔天数
	 * 
	 * @param startDate
	 *            开始日期
	 * @param endDate
	 *            结束日期
	 * @return 返回相减后的日期
	 */
	public static int minusDateForDays(Date startDate, Date endDate) {
		long endMillis = endDate.getTime();
		long startMillis = startDate.getTime();
		long s = (endMillis - startMillis) / (24 * 3600 * 1000);
		return (int) s;
	}

	/**
	 * 计算两个日期之间的天数
	 * 
	 * @param startDate
	 *            开始时间
	 * @param endDate
	 *            结束时间
	 * @return
	 */
	public static int minusDateforDays(String startDate, String endDate) {
		int days = 1;
		try {
			long start = str2Date(startDate).getTime();
			long end = str2Date(endDate).getTime();
			days = (int) ((end - start) / (24 * 60 * 60 * 1000));
		} catch (Exception e) {
			logger.error("calcDays:", e);
			return -1;
		}
		return days;
	}

	public static int minusStatisDay(Date endDate, Date startDate) {

		Calendar fromCalendar = Calendar.getInstance();
		fromCalendar.setTime(startDate);
		fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
		fromCalendar.set(Calendar.MINUTE, 0);
		fromCalendar.set(Calendar.SECOND, 0);
		fromCalendar.set(Calendar.MILLISECOND, 0);

		Calendar toCalendar = Calendar.getInstance();
		toCalendar.setTime(endDate);
		toCalendar.set(Calendar.HOUR_OF_DAY, 0);
		toCalendar.set(Calendar.MINUTE, 0);
		toCalendar.set(Calendar.SECOND, 0);
		toCalendar.set(Calendar.MILLISECOND, 0);
		Long tempString = (toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24);
		return Integer.valueOf(tempString.toString());
	}

	/**
	 * 减少年
	 * 
	 * @param date
	 * @param year
	 * @return
	 */
	public static Date minusYear(Date date, int year) {
		return addYear(date, -year);
	}

	public static Date minusMonth(Date date, int month) {
		return addMonth(date, -month);
	}

	/**
	 * 时间减去 几小时 返回时间
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static String minusHour(String strDate, int a, SimpleDateFormat dft) {
		try {
			Calendar dar = str2Calendar(strDate);
			dar.add(java.util.Calendar.HOUR_OF_DAY, -a);
			return dft.format(dar.getTime());
		} catch (Exception e) {
			logger.error("minusHour", e);
		}
		return "";
	}

	/**
	 * 时间减去 几小时 返回时间
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static String minusHourDashYyyyMMddHHmmss(String strDate, int a) {
		return minusHour(strDate, a, FMT_DATE_DASH_yyyyMMddHHmmss);
	}

	/**
	 * 功能：获取指定月的最后一天日期
	 * 
	 * @return
	 */
	public static Date previousMonthLastDay() {
		Date lastMonth = minusMonth(currentDateTime(), 1);
		Calendar c = Calendar.getInstance();
		c.set(getYear(lastMonth), getMonth(lastMonth), getMonthMaxDay(lastMonth));
		c.setTimeInMillis(c.getTimeInMillis() - (24 * 3600 * 1000));
		return c.getTime();
	}

	/**
	 * 功能：获取指定月的第一天日期
	 * 
	 * @return
	 */
	public static Date previousMonthFirtDay() {
		Date lastMonth = minusMonth(currentDateTime(), 1);
		Calendar c = Calendar.getInstance();
		c.set(getYear(lastMonth), getMonth(lastMonth), 1);
		c.setTimeInMillis(c.getTimeInMillis() - (24 * 3600 * 1000));
		return c.getTime();
	}

	/**
	 * 上个月的今天
	 * 
	 * @return
	 */
	public static Date previousMonthDay() {
		Calendar calendar = Calendar.getInstance();
		int month = calendar.get(Calendar.MONTH);
		calendar.set(Calendar.MONTH, month - 1);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		Date strDateTo = calendar.getTime();
		return strDateTo;
	}

	/**
	 * 获取前一个小时
	 * 
	 * @return
	 */
	public static Date previousHour() {
		return addHour(currentDateTime(), -1D);
	}

	/**
	 * 获取昨天信息
	 * 
	 * @return
	 */
	public static Date previousDate() {
		return addDay(currentDateTime(), -1);
	}

	/**
	 * 获取上月信息
	 * 
	 * @return
	 */
	public static Date previousMonth() {
		return addMonth(currentDateTime(), -1);
	}

	/**
	 * 获取上年信息
	 * 
	 * @return
	 */
	public static Date previousYear() {
		return addYear(currentDateTime(), -1);
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyyMMdd"格式的日期列表
	 */
	public static List<Date> dateBetween(String startDate, String endDate) {

		Calendar startCal = str2Calendar(startDate);
		Calendar endCal = str2Calendar(endDate);

		List<Date> dateList = new ArrayList<Date>();
		while (startCal.before(endCal)) {
			dateList.add(startCal.getTime());
			startCal.add(Calendar.DATE, 1);
		}
		if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {
			dateList.add(endCal.getTime());
		}
		return dateList;
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @param startDate
	 * @param endDate
	 * @param SimpleDateFormat
	 *            fmt
	 * @return
	 */
	public static List<String> dateBetween2Str(String startDate, String endDate, SimpleDateFormat fmt) {
		return dateBetween2Str(str2Calendar(startDate), str2Calendar(endDate), fmt);
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @param startDate
	 * @param endDate
	 * @param SimpleDateFormat
	 *            fmt
	 * @return
	 */
	public static List<String> dateBetween2Str(Date startDate, Date endDate, SimpleDateFormat fmt) {
		return dateBetween2Str(date2Calendar(startDate), date2Calendar(endDate), fmt);
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @param startDate
	 * @param endDate
	 * @param SimpleDateFormat
	 *            fmt
	 * @return
	 */
	public static List<String> dateBetween2Str(Calendar startDate, Calendar endDate, SimpleDateFormat fmt) {

		Calendar startCal = startDate;
		Calendar endCal = endDate;

		List<String> dateList = new ArrayList<String>();
		while (startCal.before(endCal)) {
			dateList.add(FMT_DATE_DASH_yyyyMMdd.format(startCal.getTime()));
			startCal.add(Calendar.DATE, 1);
		}
		if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {
			dateList.add(FMT_DATE_DASH_yyyyMMdd.format(endCal.getTime()));
		}
		return dateList;
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyyMMdd"格式的日期列表
	 */
	public static List<String> dateBetween2StrDashYyyyMMdd(String startDate, String endDate) {
		return dateBetween2Str(startDate, endDate, FMT_DATE_DASH_yyyyMMdd);
	}

	public static List<String> dateBetween2StrDashYyyyMMdd(Date startDate, Date endDate) {
		return dateBetween2Str(startDate, endDate, FMT_DATE_DASH_yyyyMMdd);
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyyMMdd"格式的日期列表
	 */
	public static List<String> dateBetween2StrYyyyMMdd(String startDate, String endDate) {
		return dateBetween2Str(startDate, endDate, FMT_DATE_yyyyMMdd);
	}

	public static List<String> dateBetween2StrYyyyMMdd(Date startDate, Date endDate) {
		return dateBetween2Str(startDate, endDate, FMT_DATE_yyyyMMdd);
	}

	/**
	 * 获得两个日期之间的所有月份列表（包括起始日期和结束日期）
	 * 
	 * 
	 */
	public static List<String> monthBetween2StrYyyyMM(String startYyyyMM, String endYyyyMM, SimpleDateFormat fmt) {
		Calendar startCal = str2Calendar(startYyyyMM);
		Calendar endCal = str2Calendar(endYyyyMM);

		List<String> dateList = new ArrayList<String>();
		while (startCal.before(endCal)) {
			dateList.add(fmt.format(startCal.getTime()));
			startCal.add(Calendar.MONTH, 1);
		}

		if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {
			dateList.add(fmt.format(endCal.getTime()));
		}
		return dateList;
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyyMM"格式的日期列表
	 */
	public static List<String> monthBetween2StrYyyyMM(String startDate, String endDate) {
		return monthBetween2StrYyyyMM(startDate, endDate, FMT_DATE_yyyyMMdd);
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyy-MM"格式的日期列表
	 */
	public static List<String> monthBetween2StrDashYyyyMM(String startDate, String endDate) {
		return monthBetween2StrYyyyMM(startDate, endDate, FMT_DATE_DASH_yyyyMMdd);
	}

	public static List<String> monthBetween2Str(Date time, int monthBefore, int monthAfter, SimpleDateFormat format) {
		List<String> result = new ArrayList<String>();
		Calendar calendar = Calendar.getInstance();
		if (null != time) {
			calendar.setTimeInMillis(time.getTime());
		}
		SimpleDateFormat tmpformat = format;
		if (null == tmpformat) {
			tmpformat = new SimpleDateFormat(DATE_SLASH_yyyyMM);
		}
		Calendar calendartmp = Calendar.getInstance();

		for (int i = monthBefore; i <= monthAfter; i++) {
			calendartmp.setTimeInMillis(calendar.getTimeInMillis());
			calendartmp.set(Calendar.DAY_OF_MONTH, 1);
			calendartmp.set(Calendar.HOUR_OF_DAY, 0);
			calendartmp.set(Calendar.MINUTE, 0);
			calendartmp.set(Calendar.SECOND, 0);
			calendartmp.set(Calendar.MILLISECOND, 0);

			calendartmp.add(Calendar.MONTH, i);
			result.add(tmpformat.format(new Date(calendartmp.getTimeInMillis())));
		}
		return result;

	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyyMM"格式的日期列表
	 */
	public static List<String> monthBetween2StrYyyyMM(Date time, int monthBefore, int monthAfter) {
		return monthBetween2Str(time, monthBefore, monthAfter, FMT_DATE_yyyyMMdd);
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyy-MM"格式的日期列表
	 */
	public static List<String> monthBetween2StrDashYyyyMM(Date time, int monthBefore, int monthAfter) {
		return monthBetween2Str(time, monthBefore, monthAfter, FMT_DATE_DASH_yyyyMMdd);
	}

	public static List<String> monthBetween2Str(Date from, Date to, String pattern) {
		ArrayList<String> result = new ArrayList<String>();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(from);
		Calendar calendarTo = Calendar.getInstance();
		calendarTo.setTime(getMonthLastDay(to));
		if (pattern == null) {
			pattern = DATE_SLASH_yyyyMM;
		}
		SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.ENGLISH);

		while (calendar.before(calendarTo)) {
			result.add(formatter.format(calendar.getTime()));
			calendar.add(Calendar.MONTH, 1);
		}
		return result;
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyyMM"格式的日期列表
	 */
	public static List<String> monthBetween2StrYyyyMM(Date from, Date to) {
		return monthBetween2Str(from, to, DATE_yyyyMMdd);
	}

	/**
	 * 获得两个日期之间的所有日期列表（包括起始日期和结束日期）
	 * 
	 * @return "yyyy-MM"格式的日期列表
	 */
	public static List<String> monthBetween2Str(Date from, Date to) {
		return monthBetween2Str(from, to, DATE_DASH_yyyyMMdd);
	}

	public static List<String> monthBetween2Str(Date time, int monthBefore, int monthAfter) {
		return monthBetween2Str(time, monthBefore, monthAfter, null);
	}

	public static List<String> monthBetween2Str(int monthBefore, int monthAfter) {
		return monthBetween2Str(null, monthBefore, monthAfter);
	}

	public static List<String> monthBetween2Str(int monthBefore, int monthAfter, String format) {
		return monthBetween2Str(null, monthBefore, monthAfter, new SimpleDateFormat(format, Locale.ENGLISH));
	}

	/**
	 * get months based on time, return array length is monthAfter-monthBefore+1
	 * 
	 * @param time
	 * @param monthBefore
	 * @param monthAfter
	 * @return List<Date>
	 */
	public static List<Date> monthBetween2Date(Date time, int monthBefore, int monthAfter) {
		List<Date> result = new ArrayList<Date>();
		Calendar calendar = Calendar.getInstance();
		if (null != time) {
			calendar.setTimeInMillis(time.getTime());
		}
		for (int i = monthBefore; i <= monthAfter; i++) {
			Calendar calendartmp = Calendar.getInstance();
			calendartmp.setTimeInMillis(calendar.getTimeInMillis());
			calendartmp.set(Calendar.DAY_OF_MONTH, 1);
			calendartmp.set(Calendar.HOUR_OF_DAY, 0);
			calendartmp.set(Calendar.MINUTE, 0);
			calendartmp.set(Calendar.SECOND, 0);
			calendartmp.set(Calendar.MILLISECOND, 0);
			calendartmp.add(Calendar.MONTH, i);
			result.add(new Date(calendartmp.getTimeInMillis()));
		}
		return result;
	}

	/**
	 * get months based on startMonth and endMonth, return array
	 * 
	 * @param time
	 * @param monthBefore
	 * @param monthAfter
	 * @return List<Date>
	 */
	public static List<Date> monthBetween2Date(Date startMonth, Date endMonth) {
		List<Date> result = new ArrayList<Date>();
		Calendar calendar = Calendar.getInstance();
		Calendar calendarEnd = Calendar.getInstance();
		if (null != startMonth) {
			calendar.setTimeInMillis(startMonth.getTime());
		}
		if (null != endMonth) {
			calendarEnd.setTimeInMillis(endMonth.getTime());
		}
		while (!calendar.after(calendarEnd)) {
			result.add(new Date(calendar.getTimeInMillis()));
			calendar.add(Calendar.MONTH, 1);

		}
		return result;
	}

	/**
	 * 获取当前月的前后几个月份
	 */
	public static List<Date> monthBetween2Date(int monthBefore, int monthAfter) {
		return monthBetween2Date(null, monthBefore, monthAfter);
	}

	/**
	 * 验证输入的日期是否合法
	 * 
	 * @param expDate
	 * @return
	 */
	public static boolean isValidDate(String expDate) {
		int year = Integer.parseInt(expDate.substring(0, 4));
		int month = Integer.parseInt(expDate.substring(4, 6));
		int day = Integer.parseInt(expDate.substring(6, 8));
		if (month > 12 || month < 1) {
			return false;
		}

		int[] monthLengths = new int[] { 0, 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

		if (isLeapYear(year)) {
			monthLengths[2] = 29;
		} else {
			monthLengths[2] = 28;
		}

		int monthLength = monthLengths[month];
		if (day < 1 || day > monthLength) {
			return false;
		}
		return true;
	}

	/**
	 * 是否是闰年
	 */
	private static boolean isLeapYear(int year) {
		return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
	}

	/**
	 * 判断两个Date是否同年月
	 * 
	 * @param current
	 * @param compare
	 * @return
	 */
	public static boolean isSameMonth(Date current, Date compare) {
		Calendar curr = Calendar.getInstance();
		curr.setTime(current);
		Calendar cmp = Calendar.getInstance();
		cmp.setTime(compare);
		int year1 = curr.get(Calendar.YEAR);
		int year2 = cmp.get(Calendar.YEAR);
		int month1 = curr.get(Calendar.MONTH);
		int month2 = cmp.get(Calendar.MONTH);
		return (year1 == year2) && (month1 == month2);
	}

	/**
	 * 功能：判断两个时间是否相等 精确到分
	 * 
	 * @return
	 */
	public static boolean isSameDate(String strDate, Date date) {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		return dft.format(str2Date(strDate)).equals(dft.format(date));
	}

	/**
	 * 功能：判断两个时间是否相等 精确到分
	 * 
	 * @return
	 */
	public static boolean isSameDate(Date date, String strDate) {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		return dft.format(str2Date(strDate)).equals(dft.format(date));
	}

	/**
	 * 功能：判断两个时间是否相等 精确到分
	 * 
	 * @return
	 */
	public static boolean isSameDate(Date date, Date strDate) {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		return dft.format(strDate).equals(dft.format(date));
	}

	/**
	 * 功能：判断两个时间是否相等 精确到分
	 * 
	 * @return
	 */
	public static boolean isSameDate(String date, String strDate) {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		return dft.format(str2Date(strDate)).equals(dft.format(str2Date(date)));
	}

	/**
	 * 功能：判断两个时间是否相等 精确到分
	 * 
	 * @return
	 */
	public static boolean isSameDateTime(String strDate, Date date) {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		return dft.format(str2Date(strDate)).equals(dft.format(date));
	}

	/**
	 * 判断日期是否在指定区间范围内
	 * 
	 * @param current
	 * @param before
	 * @param after
	 * @return
	 */
	public static boolean isMonthBewteen(Date current, Date before, Date after) {
		Calendar curr = Calendar.getInstance();
		curr.setTime(current);
		Calendar temp = Calendar.getInstance();
		temp.setTime(before);
		temp.set(Calendar.DAY_OF_MONTH, 1);
		temp.set(Calendar.HOUR_OF_DAY, 0);
		temp.set(Calendar.MINUTE, 0);
		temp.set(Calendar.SECOND, 0);
		if (curr.before(temp)) {
			return false;
		}
		temp.setTime(after);
		temp.add(Calendar.MONTH, 1);
		temp.set(Calendar.DAY_OF_MONTH, 1);
		temp.set(Calendar.HOUR_OF_DAY, 0);
		temp.set(Calendar.MINUTE, 0);
		temp.set(Calendar.SECOND, 0);
		if (curr.after(temp)) {
			return false;
		}
		return true;
	}

	/**
	 * 
	 * 方法用途: 结束时间（end）与start时间进行比较<br>
	 * 实现步骤: 如果相等返回0，如果end大于start返回1，如果end小于start返回-1<br>
	 * 
	 * @param start
	 * @param end
	 * @return
	 * @throws Exception
	 */
	public static int compareDate(String start, String end) {
		return compareDate(str2Date(start), str2Date(end));
	}

	/**
	 * 比较两个时间先后 （first>second返回-1，first=second返回0，first<second返回1）
	 * 
	 * @param first
	 * @param second
	 * @return
	 */
	public static int compareDate(Date first, Date second) {
		long s = first.getTime();
		long e = second.getTime();
		if (e > s) {
			return 1;
		} else if (e < s) {
			return -1;
		}
		return 0;
	}

	/**
	 * 获取位随机数 获取位随机数,为边界
	 * 
	 * @return
	 */
	public static String randomNum(String bound, int codeLlength) {
		Random r = new Random();
		int a = r.nextInt(Integer.valueOf(bound));
		String cardNum = "" + a;
		int length = cardNum.length();
		if (length < codeLlength) {
			for (int j = 0; j < (codeLlength - length); j++) {
				cardNum = "0" + cardNum;
			}
		}
		return cardNum;
	}

	/**
	 * 将Julian日期转化为date，即为哪一年的第几天
	 * 
	 * @param date
	 * @return
	 */
	public static Date Julian2Date(int date) {
		int year = (date / 1000) + 2000;
		int dayOfYear = date % 1000;
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.DAY_OF_YEAR, dayOfYear);
		return calendar.getTime();
	}

	/**
	 * 获取一年的第一天
	 * 
	 * @param date
	 * @param month
	 */
	public static Date getFirstDay4Year(Date date) {
		String dateString = getYear(date) + "-01-01";
		return str2Date(dateString);
	}

	/**
	 * 获取一年的第一天
	 * 
	 * @param date
	 * @param month
	 */
	public static Date getFirstDay4Year(Date date, int year) {
		String dateString = getYear(addYear(date, year)) + "-01-01";
		return str2Date(dateString);
	}

	/**
	 * @param string
	 * @return
	 */
	public static String time2Str(Date date) {
		return time2Str(DATE_TIME_HHmmss, date);
	}

	/**
	 * @param string
	 * @return
	 */
	public static String timestamp2Str(Date date) {
		return time2Str(DATE_TIME_HHmmssSSS, date);
	}

	/**
	 * @param string
	 * @return
	 */
	public static String time2Str(String pattern, Date date) {
		Format formatter = new SimpleDateFormat(pattern);
		return formatter.format(date);
	}

	/**
	 * @param startMonth
	 * @param i
	 * @return
	 */
	public static Date getMonthByOffset(Date date, int offset) {
		Calendar calendar = Calendar.getInstance();
		if (null != date) {
			calendar.setTime(date);
			calendar.set(Calendar.DAY_OF_MONTH, 1);
			calendar.set(Calendar.HOUR_OF_DAY, 0);
			calendar.set(Calendar.MINUTE, 0);
			calendar.set(Calendar.SECOND, 0);
			calendar.set(Calendar.MILLISECOND, 0);
		}
		calendar.add(Calendar.MONTH, offset);
		return calendar.getTime();
	}

	/**
	 * @param targetMonth
	 * @param newTargetMonth
	 * @return
	 */
	public static int compareMonth(Date first, Date second) {
		Calendar cf = Calendar.getInstance();
		cf.setTime(first);
		Calendar cs = Calendar.getInstance();
		cs.setTime(second);
		int offset = (cs.get(Calendar.YEAR) - cf.get(Calendar.YEAR)) * 12 + (cs.get(Calendar.MONTH) - cf.get(Calendar.MONTH));
		return offset;
	}

	/**
	 * 获取下一小时信息
	 * 
	 * @return
	 */
	public static Date nextHour() {
		return addHour(currentDateTime(), 1D);
	}

	/**
	 * 获取明天信息
	 * 
	 * @return
	 */
	public static Date nextDate() {
		return addDay(currentDateTime(), 1);
	}

	/**
	 * 获取下月信息
	 * 
	 * @return
	 */
	public static Date nextMonth() {
		return addMonth(currentDateTime(), 1);
	}

	/**
	 * 获取下年信息
	 * 
	 * @return
	 */
	public static Date nextYear() {
		return addYear(currentDateTime(), 1);
	}

	/**
	 * 功能：获取指定月的第一天日期
	 * 
	 * @return
	 */
	public static Date nextMonthFirtDay() {
		Date lastMonth = addMonth(currentDateTime(), 1);
		Calendar c = Calendar.getInstance();
		c.set(getYear(lastMonth), getMonth(lastMonth), 1);
		c.setTimeInMillis(c.getTimeInMillis() - (24 * 3600 * 1000));
		return c.getTime();
	}

	/**
	 * 上个月的今天
	 * 
	 * @return
	 */
	public static Date nextMonthDay() {
		Calendar calendar = Calendar.getInstance();
		int month = calendar.get(Calendar.MONTH);
		calendar.set(Calendar.MONTH, month + 1);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		Date strDateTo = calendar.getTime();
		return strDateTo;
	}

	/**
	 * 获取某天的第一时间
	 */
	public static Date beginTimeOfDate(Date date) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		Calendar calendar = calendar(date);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		return calendar.getTime();
	}

	public static Date endTimeOfDate(Date date) {
		if (NullUtils.isNull(date)) {
			return null;
		}
		return beginTimeOfDate(addDay(date, 1));
	}

	public static Date beginTimeOfDate() {
		return beginTimeOfDate(currentDateTime());
	}

	public static Date endTimeOfDate() {
		return endTimeOfDate(currentDateTime());
	}

	/**
	 * 获取一年的第一天
	 * 
	 * @param date
	 * @param month
	 */
	public static Date beginTimeOfYear(Date date) {
		String dateString = getYear(date) + "-01-01";
		return str2Date(dateString);
	}

	/**
	 * 获取一年的第一天
	 * 
	 * @param date
	 * @param month
	 */
	public static Date endTimeOfYear(Date date, int year) {
		String dateString = getYear(addYear(date, year)) + "-01-01";
		return str2Date(dateString);
	}

	public static Date beginTimeOfYear() {
		return beginTimeOfDate(currentDateTime());
	}

	public static Date endTimeOfYear(int year) {
		return endTimeOfDate(currentDateTime());
	}
}
